/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2021-11-01 22:28:02
 * @LastEditors: TT
 * @LastEditTime: 2023-03-10 22:04:15
 */

import 'package:flutter/material.dart';
import 'package:ttcomment/ttcomment.dart';

/// 刷新界面 规范
abstract class AbstracRefreshWidget {
  /// 创建刷新控件
  Widget createRefreshWidget(BuildContext context);

  /// 创建列表
  Widget createListView(BuildContext context);

  /// 创建列表 item
  Widget createListitem(BuildContext context, int index);

  /// 创建缺省页界面
  Widget? createEmptyWidget();
}

/// 刷新界面 触发方法
abstract class AbstracRefreshMehod {
  int page = 1;

  /// 结束刷新
  void endRefresh(int type, PageState pageState);

  /// 下啦刷新 触发事件
  void configRefresh();

  /// 上啦加载 触发事件
  void configLoading();
}

abstract class AbstractAttribute {
  /// 导航栏标题
  final String? title = null;

  /// 导航栏颜色
  final Color? navbackcolor = null;

  /// 默认安全区顶部 忽略
  final bool safeAreatop = true;

  /// 默认安全区底部 忽略
  final bool safeAreabottm = true;

  /// 网络加载状态
  final PageState pageState = PageState.initializedState;

  /// 背景颜色
  final Color? backgroundColor = null;

  /// 是否显示Scaffol脚手架
  final bool isneedScaffol = true;

  /// 滚动属性
  final bool? resizeToAvoidBottomInset = null;
}

// 配置网络请求规范
abstract class AbstractNetWork {
  @protected
  Map<String, dynamic>? configNetWorkParmas();

  /// 网络请求
  @protected
  void getnetworkdata({
    int? type,
    Map<String, dynamic>? info,
  });
}

// 普通界面 规范
abstract class AbstractWidget {
  /// 创建scaffoll
  Widget createScaffol({
    required BuildContext context,
    required bool safeAreatop,
    required bool safeAreabottm,
    required PageState pageState,
    required String? title,
    required Color? backgroundColor,
    required Color? navbackcolor,
    required bool? resizeToAvoidBottomInset,
    bool? isneedScaffol = true,
  }) {
    return isneedScaffol!
        ? Scaffold(
            resizeToAvoidBottomInset: resizeToAvoidBottomInset,
            backgroundColor: backgroundColor,
            appBar: createAppBar(
              context,
              title: title,
              navbackcolor: navbackcolor,
            ),
            body: createSafeArea(
              context,
              safeAreatop,
              safeAreabottm,
              pageState,
            ),
          )
        : createSafeArea(
            context,
            safeAreatop,
            safeAreabottm,
            pageState,
          );
  }

  /// 创建导航栏
  PreferredSize? createAppBar(
    BuildContext context, {
    Color? navbackcolor,
    String? title,
  }) {
    if (title != null) {
      return AppBarGenerator.getNoramlAppBar(
        context: context,
        title: title,
        backgroundColor: navbackcolor,
        actions: createAppBaractions(),
        leading: createAppBarleading(),
        textColor: createAppBarTextColor(),
        leadingIconColor: createLeadingIconColor(),
        leadingCallback: () {
          configleadingCallbak(context);
        },
        titlew: createAppBarTitleWidget(),
        bottom: createAppBarBottomWidget(),
      );
    }
    return null;
  }

  /// 自定义appBar title
  Widget? createAppBarTitleWidget() {
    return null;
  }

  /// 设置系统返回按钮 icon 颜色
  Color? createLeadingIconColor() {
    return null;
  }

  /// 设置默认 title 字体颜色
  Color? createAppBarTextColor() {
    return null;
  }

  /// 创建导航栏 右边按钮集合
  List<Widget>? createAppBaractions() {
    return null;
  }

  /// 重写返回按钮控件
  Widget? createAppBarleading() {
    return null;
  }

  /// 创建AppBar bottom
  PreferredSizeWidget? createAppBarBottomWidget() {
    return null;
  }

  /// 创建safe
  Widget createSafeArea(
    BuildContext context,
    bool safeAreatop,
    bool safeAreabottm,
    PageState pageState,
  ) {
    return SafeArea(
      child: createCommBaseWidget(
        context,
        pageState,
      ),
      top: safeAreatop,
      bottom: safeAreabottm,
    );
  }

  /// 创建通用站位界面
  Widget createCommBaseWidget(
    BuildContext context,
    PageState pageState,
  ) {
    return CommonBasePage(
      pageState: pageState,
      child: createColumWidget(context),
      errorWidget: createErrorWidget(),
      loadingWidget: createLoadingWidget(),
      isshowloading: configIsshowLoading(),
    );
  }

  /// 创建界面Colum
  Widget createColumWidget(
    BuildContext context,
  ) {
    return Column(
      children: [
        createHeaderWidget(),
        Expanded(
          child: createBody(context),
        ),
      ],
    );
  }

  /// 创建头部
  Widget createHeaderWidget() {
    return Container();
  }

  /// 创建真实body
  @protected
  Widget createBody(
    BuildContext context,
  );

  /// 创建失败 界面
  Widget? createErrorWidget() {
    return null;
  }

  /// 创建加载界面
  Widget? createLoadingWidget() {
    return null;
  }

  bool configIsshowLoading() {
    return false;
  }

  /// 点击通用返回按钮点击事件
  configleadingCallbak(
    BuildContext context,
  ) {
    configgoback(context);
  }

  /// 执行返回界面
  configgoback(
    BuildContext context,
  ) {
    Navigator.of(context).pop();
  }
}
